package cn.edu.cjw.APMFP.Util;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ResourceBundle;

import org.junit.Test;

public class SelectExist {

	public static Boolean selectExist(String tablename, String whereLine, String whereValue) throws SQLException {

		boolean flag = false;

		ResourceBundle bundle = ResourceBundle.getBundle("System");
		String hive_url = bundle.getString("Hive-url");
		String hive_user = bundle.getString("Hive-user");
		String hive_password = bundle.getString("Hive-password");

		Connection conn = HiveUtill.getConn(hive_url, hive_user, hive_password);

		String sql = "SELECT count(0) count FROM " + tablename + " where " + whereLine + "=?";
		PreparedStatement ps = conn.prepareStatement(sql);

		ps.setString(1, whereValue);

		ResultSet RS = ps.executeQuery();

		while (RS.next()) {
			int count = RS.getInt(1);

			if (count > 0) {

				flag = true;

			}

		}
		HiveUtill.Close(RS, ps, conn);
		return flag;
	}

}
